<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var palindromePairs = function (words) {
      let i = 0, arr = [];
      var length = words.length;
      while (i < length) {
        for (let k = 0; k < length; k++) {
          if (i === k) continue;
          const str = words[i] + words[k];
          if (isPalindrom(str)) {
            arr.push([i, k])
          }
        }
        i++;
      }
      return arr;
    };
    // 判断是否是回文字符串
    function isPalindrom(str) {
      let i = 0, j = str.length - 1
      while (i < j) {
        if (str[i] !== str[j]) {
          return false
        }
        i++
        j--
      }
      return true
    }
    console.log(palindromePairs(words = ["abcd", "dcba", "lls", "s", "sssll"]))
  </script>
</body>

</html>